<%--
  Created by IntelliJ IDEA.
  User: fengdefangxiang
  Date: 2022/1/13
  Time: 19:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="/web/header.jsp" %>
    <style>
        body {
            background: url('<%=app%>/web/base/img/background.jpg') no-repeat;
            background-size: cover;
        }
    </style>
</head>
<div class="window">
    <fieldset class="layui-elem-field" style="margin: 10px">
        <legend>注册</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="code" required lay-verify="required" placeholder="请输入账号"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="pass" required lay-verify="required" placeholder="请输入密码"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <input type="button" value="注册" class="layui-btn" lay-submit lay-filter="reg">
                        <input type="reset" class="layui-btn layui-btn-primary">
                    </div>
                    <input type="button" value="返回登陆" class="layui-btn" onclick="toHref('/web/login.jsp')">
                </div>
                <input type="hidden" name="action" value="reg">
            </form>
        </div>
    </fieldset>
</div>
<script type="text/javascript">
    // let form = layui.form; // 绑定表单，获得表单数据
    // let $ = layui.jquery;  //将jquery的$符号拿出来用，也可以导入jquery的js
    // let layer = layui.layer;
    //form.on("submit(reg)", function (data) { // 点击注册按钮会执行
    //console.log(data.field) //data.field ：得到数据，是一个对象
    // $.ajax({
    //     url: base.app + "/EmployeeServlet",
    //     type: "post",
    //     data: data.field, // a=b&c=d / {a:b,c:d}
    //     dataType: "json",
    //     success: function (data) {
    //         //      console.log(data)
    //         if (data == 1) {
    //             layer.msg("注册成功");
    //         }else if (data=="repeat"){
    //             layer.msg("注册失败,账号重复");
    //         }
    //         else {
    //             layer.msg("注册失败");
    //         }
    //     }
    // });
    formOnSubmit('reg', '/EmployeeServlet', 'text', function (data) {
        if (data == 1) {
            layer.msg("注册成功");
        } else if (data == "repeat") {
            layer.msg("注册失败,账号重复");
        } else {
            layer.msg("注册失败");
        }
    })

</script>
</body>
</html>
